package com.essence.common.model.parser;

import com.essence.common.model.Packet;
import io.netty.buffer.ByteBuf;

/**
 * @brief 单点遥信: 无时标
 */
public class MSpNaParser extends ByteBufParser {
    @Override
    void parse(Packet packet, ByteBuf buf) {
        if (packet.getVsq().getSq() == 0) {
            for (int i = 0; i < packet.getVsq().getNum(); i++) {
                int infoAdr = buf.readUnsignedMediumLE();
                byte qb = buf.readByte();
                Packet.DigitalSignals digitalSignals = new Packet.DigitalSignals(infoAdr, qb, 1, null);
                packet.addDigitalSignals(digitalSignals);
            }
        }
        if (packet.getVsq().getSq() == 1) {
            int infoAdr = buf.readUnsignedMediumLE();
            for (int i = 0; i < packet.getVsq().getNum(); i++) {
                byte qb = buf.readByte();
                Packet.DigitalSignals digitalSignals = new Packet.DigitalSignals(infoAdr + i, qb, 1, null);
                packet.addDigitalSignals(digitalSignals);
            }
        }
    }

    @Override
    int infoObjectLength() {
        return 4;
    }
}
